<template>
    <div class="cinema-detial">
        <div class="nav">
            <div class="back" @click.stop="$router.back()">
                <i class="iconfont icon-fanhui"></i>
            </div>
            <h1 v-if="cinema">{{cinema.nm}}</h1>
        </div>
        <div class="detial" v-if="cinema">
            <div class="cinemaLocation">
                <h2>{{cinema.nm}}</h2>
                <p>{{cinema.addr}}</p>
            </div>
            <div class="banner">
                <swiper class="swiper" :options="swiperOption" ref="mySwiper" @slideChangeTransitionEnd="slide" @click-slide="bannerClick">
                    <swiper-slide v-for="(imgUrl,index) in imgs" :key="index" :class="['imgSize',index==chooseIndex?'choosed':'']">
                        <img :src="imgUrl"/>
                    </swiper-slide>
                </swiper>
                <dir class="bg" :style="{'backgroundImage':`url(${imgs[chooseIndex]})`}"></dir>
            </div>

            <div class="name">
                <div v-for="(item,index) in movies" :key="item.id">
                    <p class="nms" v-if="index==chooseIndex">
                        {{item.nm}}
                        <span class="score">
                            <span v-if="item.sc!='0.0'">{{item.sc}}</span>
                            <span v-else-if="item.sc=='0.0'&& item.wish>10000">{{item.wish}}</span>
                            <span v-else>暂无评分</span>
                            <span class="person" v-if="item.sc!='0.0'">分</span>
                            <span class="person" v-else-if="item.sc=='0.0'&& item.wish>10000">人想看</span>
                        </span>
                    </p>
                    <p class="title" v-if="index==chooseIndex">
                        {{item.desc}}
                    </p>
                </div>
            </div>

            <div class="show">
                <van-tabs swipe-threshold="3" title-active-color="#f03d37" title-inactive-color="#666" line-width="80" v-if="movies[chooseIndex] && movies[chooseIndex].shows">
                    <van-tab v-for="(item,index) in movies[chooseIndex].shows" :title="item.showDate|filDate" :key="index">
                        <div class="vipInfo">
                            <van-tag type="warning" text-color="#fff">折扣</van-tag>
                            <p>{{cinema.vipInfo.desc}}</p>
                            <span>23.9元起开卡</span>
                        </div>
                        <ul class="plist">
                            <li v-for="lis in item.plist" :key="lis.seqNo">
                                <plice-list :lis="lis" :dur="movies[chooseIndex].dur" :cinema="cinema" :movie="movies[chooseIndex]"></plice-list>
                            </li>
                        </ul>
                    </van-tab>
                </van-tabs>
            </div>
        </div>
    </div>
</template>

<script>
import {mapGetters} from 'vuex'
import { Swiper, SwiperSlide } from "vue-awesome-swiper"
import "swiper/css/swiper.css"
import PliceList from '../components/PliceList.vue'

export default {
    props:['cinemaId'],
    data(){
        return{
            cinema:null,
            movies:[],
            imgs:[],
            swiperOption: {
                slidesPerView: 5,
                spaceBetween: 15,
                centeredSlides: true,
                slideToClickdSlide:true,
            },
            chooseIndex:0,
        }
    },
    created(){
        this.getdetail();
        this.getshow();
    },
    methods:{
        async getdetail(){
            let re=await this.axios.get('cinema/detail?cinemaId='+this.cinemaId);
            this.cinema=re.data.data;
        },
        async getshow(){
            let re=await this.axios.get(`cinema/shows?cinemaId=${this.cinemaId}&ci=${this.cityid}&channelId=4`);
            this.movies=re.data.data.movies;
            let arr=this.movies.map(item=>{
                return item.img.replace('w.h','148.209');
            });
            this.imgs.push(...arr);
        },
        slide() {
            this.chooseIndex=this.$refs.mySwiper.$swiper.activeIndex;
        },
        bannerClick(){
            let index=this.$refs.mySwiper.$swiper.clickedIndex;
            this.$refs.mySwiper.$swiper.slideTo(index, 0);
        }
    },
    computed:{
        ...mapGetters(['cityid']),
    },
    filters:{
        filDate(text){
            let now=new Date();
            let date=new Date(text);
            let m=date.getMonth()+1;
            let d=date.getDate();
            let week=['周日','周一','周二','周三','周四','周五','周六'];
            if(date.getDay()-now.getDay()==0){
                return '今天'+m+'月'+d+'日';
            }else if(date.getDay()-now.getDay()==1){
                return '明天'+m+'月'+d+'日';
            }else{
                return week[date.getDay()]+m+'月'+d+'日';
            }
        },
    },
    components: {
        Swiper,
        SwiperSlide,
        PliceList,
    },
}
</script>

<style lang="less">
.cinema-detial{
    background-color: #fff;

    .nav{
        position: sticky;
        top: 0;
        left: 0;
        z-index: 3;
        background-color: #e54847;
        padding: 6px;
        height: 38px;
        line-height: 38px;
        color: #fff;
        text-align: center;
        font-size: 18px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;

        .back{
            position: absolute;
            left: 16px;
            top: 50%;
            transform: translateY(-50%);

            i{
                font-size: 20px;
            }
        }
    }

    .cinemaLocation{
        padding: 16px;
        overflow: hidden;

        h2{
            font-size: 17px;
            color: #333;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-weight: 600;
        }

        p{
            font-size: 13px;
            color: #999;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding-top: 10px;
        }
    }

    .banner{
        height: 135px;
        z-index: 2;
        position: relative;
        overflow: hidden;
        
        .bg{
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-repeat: no-repeat;
            background-size: cover;
            background-position: 50%;
            transform: scale(1.5);
            filter: blur(30px);

            &::after{
                content: "";
                position: absolute;
                width: 100%;
                height: 100%;
                left: 0;
                top: 0;
                background-color: rgba(0, 0, 0, 0.3);
            }
        }

        .swiper{
            height: 100%;

            .swiper-wrapper{
                height: 100%;
                // display: flex;
                align-items: center;
            }

            .imgSize{
                width: 65px !important;
                height: 95px;
                transform-origin: center;

                img{
                    width: 100%;
                    height: 100%;
                    display: block;
                    transform-origin: center;
                }

                &.choosed{
                    transform: scale(1.15);
                    border: 2px solid #fff;
                    position: relative;

                    &::after{
                        content: "";
                        position: absolute;
                        border: 5px solid transparent;
                        border-top-color: #fff;
                        left: 50%;
                        bottom: -11px;
                        transform: translateX(-50%);
                    }
                }
            }
        }
    }

    .name{
        padding: 16px;
        overflow: hidden;
        text-align: center;
        position: relative;

        &::after{
            content: "";
            width: 100%;
            position: absolute;
            left: 0;
            bottom: 0;
            border-bottom: 1px solid #eee;
        }
        
        .nms{
            font-size: 17px;
            color: #333;
            font-weight: 600;

            .score{
                font-size: 16px;
                color: #ffb400;

                .person{
                    font-size: 12px;
                }
            }
        }

        .title{
            color: #999;
            font-size: 13px;
            padding-top: 10px;
        }
    }

    .show{
        .vipInfo{
            background-color: #fff5ea;
            padding: 0 15px;
            display: flex;
            font-size: 12px;
            align-items: center;
            height: 40px;
            position: relative;

            &::after{
                position: absolute;
                content: "";
                width: 100%;
                border-bottom: 1px solid #eee;
                left: 0;
                bottom: 0;
            }

            p{
                color: #fa9600;
                flex: 1;
                margin-left: 10px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }

            span{
                margin-left: 3px;
                color: #999;
            }
        }

    }
}
</style>